package P4.T05;

import java.util.ArrayList;
import java.util.List;

public class T05 {
    private static Integer[] getInts(String str)throws NumberFormatException{
        List<Integer> ints = new ArrayList<>();
        int start = 0, end = 0;
        //try {
            while (start < str.length()) {
                while (!Character.isDigit(str.charAt(start)) && start < str.length() - 1) start++;
                end = start + 1;
                while (end < str.length() && Character.isDigit(str.charAt(end))) end++;
                ints.add(Integer.parseInt(str, start, end, 10));
                start = end;
            }
//        } catch (NumberFormatException e) {
//            System.out.println("存在超出范围的整数");
//            return null;
//        }
        return ints.toArray(new Integer[]{});
    }
    public static void main(String[] args) {
        Integer[] ints;
        try {
            ints = getInts("00123 4561234566 o789uu987");
            for (Integer i : ints)System.out.println(i);
        } catch (NullPointerException e) {}//有可能是空数
        catch(NumberFormatException e) {
            System.out.println("数值超出范围");
        }

    }

}
